<script>
$(document).ready(function(){
var id_user = $('#id_user').val();

var id_sale = $('#id_sale').val();	
$.post("<?= site_url('accounts/money_receipt/get_invoiceno')?>",{ id_user:id_user }, function(msg){
	if(msg){
				jQuery('#areas').empty().append(msg);
				$("#areas").val(id_sale);
				jQuery('#areas').trigger("liszt:updated");
			//document.getElementById("areas").innerHTML = msg;	

	}
		
})

})
</script>
<script>

function get_invoiceno(id_user){
		$.post("<?= site_url('accounts/money_receipt/get_invoiceno')?>",{ id_user:id_user }, function(msg){
		if(msg){
				jQuery('#areas').empty().append(msg);
				jQuery('#areas').trigger("liszt:updated");
			//document.getElementById("areas").innerHTML = msg;	

		}
		
		})	
}

function get_amount(id_sale){
		$.post("<?= site_url('accounts/money_receipt/get_amount')?>",{ id_sale:id_sale }, function(msg){
		if(msg){
				$("#credit_amount").val(msg);	

		}
		
		})	
}

function hi(id,type){
	if(id.checked){
		if(type==1){
			$('.dd').show()		
		}else{
			$('#cheque_no').val('')
			$('#id_bank').val('0')
			$('.dd').hide()
			
		}
		
	}

</script>

<h2 style="background-color:#368EE0; color:white; font-size:20px; padding:5px;">Update Money Receipt</h2>

<br>
<br>

<div id="infoMessage"><?php echo $message;?></div>
<?php echo form_open(current_url());?>
     <table width="60%" align="center" class="table-condensed">  
        <tr>
         <td> <b>Customer:</b> </td>
         <td>
     <select name="id_user" id="id_user" onchange="get_invoiceno(this.value);" class="span6 chzn-select">
    <option value="0">-- Warehouse -- </option>
    <?php foreach ($customers as $customer) {?>
    <option value="<?=$customer->id?>" <?php 
	if($user['id_user'] == $customer->id)
	{
		echo 'selected = "selected"';
		
	}
	
	?> ><?= $customer->username;?></option >
    <?php } ?>
    </select></td>
    </tr>
	<tr>
	<td><b>Invoice No</b></td>
	<td><select id="areas" class="span6 chzn-select" name="voucher_no" onchange="get_amount(this.value);">
	</select>
	<input type="hidden" id="id_sale" value="<?= $user['id_sale']?>">
	</td>
	</tr>
	<tr>
	<td><b>Credit Amount</b></td><td><input type="text" id="credit_amount"  name="credit_amount" value="<?= $user['credit_amount']?>" ></td>
	</tr>
		<tr>
	<td><b>Deposit By</b></td><td><label class="radio"><input type="radio" id="payment_type" name="payment_type" value='0' <?php if($user['payment_type']==0){?> checked <?php }?>  onchange="hi(this, this.value);"  name="payment_type">:Cash&nbsp;&nbsp;&nbsp;</label><label class="radio"><input type="radio" value='1' name="payment_type" id="payment_type" <?php if($user['payment_type']==1){?> checked <?php }?> onchange="hi(this, this.value);"  name="type">:Cheque/Draft</label></td>
	</tr>
	<tr class="dd" >
	<td><b>Checque/draft No</b></td>
	<td><input type="text" name="cheque_no" value="<?= $user['cheque_no']?>"></td>
	</tr>
	<tr class="dd" >
	<td><b>Select Bank</b></td>
	<td>  <select name="bank_name"  class="chzn-select">
    <option value="0">-- bank -- </option>
    <?php foreach ($banks as $bank) {?>
    <option value="<?=$bank->name?>" <?php 
	if($user['bank_name'] == $bank->name)
	{
		echo 'selected = "selected"';
		}
	?> ><?= $bank->name;?></option >
    <?php } ?>
    </select></td>
	</tr>
	
	<tr> <td><b>  Date: </b></td>
            <td><input type="text" name="date" class="datepicker" value="<?= $user['date']?>"></td>
    </tr>
<tr><td>&nbsp;</td> <td><?php echo form_submit('submit', 'Add salesman', 'class="btn btn-success"');?></td></tr>
</table>
<?php echo form_close();?>
